<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>用户管理</title>
<script src="${ctx}/static/selectWin/employeeSelector.js?version=${applicationScope.jsVersion }" type="text/javascript"></script>
<script type="text/javascript">
	var SelectedUser;
	var $grid;
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			toolbar : "#toolbar",
			method : "get",
			singleSelect : true,
			pagination : true,
			url : "${ctx}/basic/user/dataGrid",
			fitColumns : false,
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'loginNo',
				title : '登录账号',
				width : 80,
				sortable : true
			}, {
				field : 'trueName',
				title : '姓名',
				width : 80,
				sortable : true
			}/*,  {
																field : 'postName',
																title : '岗位',
																width : 100,
																formatter : function fmt_sn(val, row) {
																	return row.staffinfo ? row.staffinfo.post.postName : "";
																},
																sortable : true
															},  
			{
				field : 'userType',
				title : '用户类型',
				width : 80,
				sortable : true
			}*/ ] ],
			onClickRow : function(rowIndex, rowData) {
				selectTableRow = rowData;
			}
		}));
		$grid.datagrid('enableFilter', [ {
			field : 'idCardNo',
			type : 'text',
			searchField : 'employee.idCardNo'
		}, /* {
									field : 'postName',
									type : 'text',
									searchField : 'staffinfo.post.postName'
								}, */{
			field : 'orgName',
			type : 'text',
			searchField : 'employee.org.orgName'
		} ]);
		$("#excelExport").click(function() {
			var url = "${ctx}/basic/user/excelExport?" + $.param($("#grid").datagrid('options').queryParams);
			if ($("#grid").datagrid("options").filterRules) {
				url += "&filterRules=" + JSON.stringify($("#grid").datagrid("options").filterRules);
			}
			window.parent.location.href = url;
		});
		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/basic/user/multiDelete");
		});
		//选择列表
		fn_initComboNotId("userType", "userType", true);//付款方式
		$("#staffinfoSelector").click(function() {
			$.easyui.showGridSelector($.extend(staffinfoSelectOpts, {
				onEnter : function(val) {
					if (val) {
						$("#staffinfo").val(val.id);
						$("#loginNo").val(val.jobNumber);
						$("#trueName").val(val.staffName);
						$("#jobNumber").val(val.jobNumber);
						$("#phoneNumber").val(val.phoneNumber);
						$("#workPhone").val(val.workPhone);
						$("#identityCardNo").val(val.identityCardNo);
						$("#shortNumber").val(val.shortNumber);
						$("#postName").val(val.post.postName);
						$("#orgName").val(val.organization.orgName);
					}
				}
			}));
		});
		$("#employeeSelector").click(function() {
			$.easyui.showGridSelector($.extend(employeeSelectOpts, {
				onEnter : function(val) {
					if (val) {
						$("#employee").val(val.id);
						$("#name").val(val.trueName);
						$("#loginNo").val(val.jobNumber);
						$("#trueName").val(val.trueName);
						$("#identityCardNo").val(val.idCardNo);
					}
				}
			}));
		});
	});

	function fun_user_add() {
		$("#dlg").dialog("open").dialog("setTitle", "新增员工用户");
		$("#fm").form("clear");
		$("#pass").val("88888888");
	}
	function fun_user_edit() {
		var rowData = $("#grid").datagrid("getSelected");
		if (rowData == null) {
			showAlert("您未选择任何记录!");
		} else {
			$("#dlg").dialog("open").dialog("setTitle", "编辑用户--[" + rowData.trueName + "]");
			$("#fm").form("clear");
			if (rowData.employee) {
				$("#fm").form("load", $.extend(rowData, {
					identityCardNo : rowData ? rowData.employee.idCardNo : "",
					name : rowData ? rowData.employee.trueName : "",
					employee : rowData ? rowData.employee.id : ""
				}));
			}else{
				$("#fm").form("load", rowData);
			}
			rowData.userType && fn_setValueForComboBox("userType", rowData.userType, rowData.userType, true);
		}
	}
	function fun_user_save() {
		$("#fm").form("submit", {
			url : "${ctx}/basic/user/update",
			success : function(data) {
				if (data.success) {
					$("#dlg").dialog("close");
					$("#grid").datagrid("load");
				}
				showInfo(data.msg);
			}
		});
	}
	function fun_user_savemm() {
		$("#pass").val("888888");
		$("#fm").form("submit", {
			url : "${ctx}/basic/user/update",
			success : function(data) {
				if (data.success) {
					$("#dlg").dialog("close");
					$("#grid").datagrid("load");
				}
				showInfo(data.msg);
			}
		});
	}
</script>
</head>
<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true">
		</table>
		<div id="toolbar" class="row">
			<div class="col-md-12">
				<!-- 功能按钮 -->
				<shiro:hasPermission name="user:update">
					<button id="btn-add" type="button" class="btn btn-primary" onclick="fun_user_add()">
						<span class="glyphicon glyphicon-plus"></span> 新增员工用户
					</button>
					<button id="btn-edit" type="button" class="btn btn-primary" onclick="fun_user_edit()">
						<span class="glyphicon glyphicon-pencil"></span> 修改
					</button>
				</shiro:hasPermission>
				<shiro:hasPermission name="user:delete">
					<button id="delete" type="button" class="btn btn-danger">
						<span class="glyphicon glyphicon-minus"></span> 删除
					</button>
				</shiro:hasPermission>
				<!--<shiro:hasPermission name="user:import">
				<a id="excelImport" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-page-white-excel'">Excel导入</a>
			</shiro:hasPermission>-->
				<shiro:hasPermission name="user:export">
					<button id="excelExport" type="button" class="btn btn-primary">
						<span class="glyphicon glyphicon-save"></span> Excel导出
					</button>
				</shiro:hasPermission>
			</div>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog" style="width: 670px; height: 300px; padding: 10px 20px"
		data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
		<form id="fm" method="post">
			<input id="id" name="id" type="hidden" /> <input id="employee" name="employee" type="hidden" /> 
			<table id="tbl">
				<tr>
					<td><label>员工选择:</label></td>
					<td><input id="name" name="name" class="easyui-validatebox" readonly="readonly" /> <a id="employeeSelector"
						class="easyui-linkbutton easyui-tooltip" data-options="plain: true, iconCls: 'icon-metro-search',content:'关联员工'"></a></td>
				</tr>
				<tr>
					<td><label>登陆账号:</label></td>
					<td><input id="loginNo" name="loginNo" class="easyui-validatebox" data-options="required:true" /></td>
					<td><label>密码:</label></td>
					<td><input id="pass" name="plainPassword" type="password" class="easyui-validatebox" readonly="readonly" /></td>
				</tr>
				<tr>
					<td><label>姓名:</label></td>
					<td><input id="trueName" name="trueName" class="easyui-validatebox" data-options="required:true" readonly="readonly" /></td>
					<!-- <td><label>岗位:</label></td>
					<td><input id="postName" name="postName" class="easyui-validatebox" readonly="readonly"></td> -->
					<!-- <td><label>所属组织:</label></td>
					<td><input id="orgName" name="orgName" class="easyui-validatebox" readonly="readonly"></td> -->
				</tr>
			</table>
		</form>

		<div id="dlg-btn">
			<button id="add" type="button" class="btn btn-primary" onclick="fun_user_savemm();">
				<span class="glyphicon glyphicon-ok"></span> 初始化密码并保存
			</button>
			<button id="add" type="button" class="btn btn-primary" onclick="fun_user_save();">
				<span class="glyphicon glyphicon-ok"></span> 保存
			</button>
			<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
				<span class="glyphicon glyphicon-remove"></span> 取消
			</button>
		</div>
	</div>
</body>
</html>
